﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//.............
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//...................

namespace QLKTX1._0.DAO
{
    class ThangDAO
    {
        public static List<ThangDTO>dsThang()
        {
            List<ThangDTO> sdThang = new List<ThangDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM Thang");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ThangDTO thang = new ThangDTO();

                thang.MaThang = dt.Rows[i]["maThang"].ToString();

                thang.TenThang = dt.Rows[i]["tenThang"].ToString();

                sdThang.Add(thang);
                
            }
            return sdThang;
        }
        //ham Insert
        public static bool themThang(ThangDTO thang)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO Thang(maThang,tenThang) VALUES('" + thang.MaThang + "','" + thang.TenThang + "')");

        }
        //Ham delete
        public static bool xoaThang(ThangDTO thang)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("DELETE FROM Thang WHERE maThang='" + thang.MaThang  + "'");

        }
        //Ham update
        public static bool capNhatThang(ThangDTO thang)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("UPDATE Thang set tenThang='" + thang.TenThang + "' WHERE maThang='" + thang.MaThang + "'");

        }

    }
}
